package com.java110.mall.cart.cmd.storeOrder;

import com.alibaba.fastjson.JSONObject;
import com.java110.mall.cart.bmo.storeOrderCart.IUpdateStoreOrderCartBMO;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.po.storeOrder.StoreOrderCartPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

/**
 * 收货确认
 *
 * 如果收货了就分账了
 */
@Java110Cmd(serviceCode = "/storeOrder/receiveStoreOrderCart")
public class ReceiveStoreOrderCartCmd extends Cmd {

    @Autowired
    private IUpdateStoreOrderCartBMO updateStoreOrderCartBMOImpl;

    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
        Assert.hasKeyAndValue(reqJson, "orderId", "请求报文中未包含orderId");
        Assert.hasKeyAndValue(reqJson, "personId", "请求报文中未包含personId");
        Assert.hasKeyAndValue(reqJson, "cartId", "cartId不能为空");
        Assert.hasKeyAndValue(reqJson, "shopId", "shopId不能为空");
    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
        StoreOrderCartPo storeOrderCartPo = BeanConvertUtil.covertBean(reqJson, StoreOrderCartPo.class);
        ResponseEntity responseEntity = updateStoreOrderCartBMOImpl.receiveOrderCart(storeOrderCartPo);
        cmdDataFlowContext.setResponseEntity(responseEntity);
    }
}
